package day10;

public class Homework3 {
    int n=1;
    int count1=0;
    int count2=0;
    int count3=0;
    public synchronized void printA(){
        if(n==1){
            System.out.println(Thread.currentThread().getName());
            n=2;
            count1++;
        }
    }
    public synchronized void printB(){
        if(n==2){
            System.out.println(Thread.currentThread().getName());
            n=3;
            count2++;
        }
    }
    public synchronized void printC(){
        if(n==3){
            System.out.println(Thread.currentThread().getName());
            n=1;
            count3++;
        }
    }
    public static void main(String[] args) {
        Homework3 h = new Homework3();
        new Thread(()->{
            while (h.count1<5){
                h.printA();
            }
        },"A").start();
        new Thread(()->{
            while (h.count2<5){
                h.printB();
            }
        },"B").start();
        new Thread(()->{
            while (h.count3<5){
                h.printC();
            }
        },"C").start();
    }
}
